package com.yumingjaing.stream;

import com.yumingjaing.mockito.Student1;
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

//分区
public class CollectDemo {

    /**
     * 数据分区
     */
    @Test
    public void testCollect() {
        Stream<Student1> studentStream = Stream.of(
                new Student1("张三", 19, "男", "北京", 90.50),
                new Student1("李四", 20, "女", "上海", 80.50),
                new Student1("王五", 21, "男", "北京", 70.50),
                new Student1("赵六", 22, "女", "北京", 60.50),
                new Student1("孙七", 23, "男", "上海", 50.50)
        );
        Map<Boolean, List<Student1>> map = studentStream.collect(Collectors.partitioningBy(s -> {
            return s.getScore() >= 70;
        }));
        map.forEach((k, v) -> {
            System.out.println(k + "----" + v);
        });


    }
}

